﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace BreakArray
{
    class Piece : Image
    {
        // Piece specific variables
        Texture2D player1Piece;
        Texture2D player2Piece;
        int state;


        private enum State
        {
            Blank = 0,
            Player1 = 1,
            Player2 = 2
        }

        // Constructor
        public Piece()
        {
            //Nothing to look at here
        }

        // Initialize all required variables
        public void Initialize(Vector2 pos, Rectangle src,
                                Vector2 origin, Vector2 scale,
                                Single depth)
        {
            // Initialize user defined variables
            this.position = pos;
            this.source = src;
            this.origin = origin;
            this.depth = depth;
            this.scale = scale;
        }

        //Load all required graphics content
        public void LoadContent(SpriteBatch spriteBatch, Texture2D player1,
                                Texture2D player2)
        {
            this.spriteBatch = spriteBatch;
            this.player1Piece = player1;
            this.player2Piece = player2;
        }

        // Set the state directly with no animations
        public void SetPosition(int toState)
        {
            this.state = toState;
        }

        // Return the value of the current state
        public int Value()
        {
            return state;
        }
        // Draw to the screen
        new public void Draw()
        {
            switch (state)
            {
                case 0:
                    // Dont draw anything (blank)
                    break;
                case 1:
                    spriteBatch.Begin();
                    spriteBatch.Draw(this.player1Piece, this.position, this.source,
                                        this.color, this.rotation, this.origin,
                                        this.scale, this.effects, this.depth);
                    spriteBatch.End();
                    break;
                case 2:
                    spriteBatch.Begin();
                    spriteBatch.Draw(this.player2Piece, this.position, this.source,
                                     this.color, this.rotation, this.origin,
                                     this.scale, this.effects, this.depth);
                    spriteBatch.End();
                    break;
            }
        }
    }
}
